﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using DLL;
using System.Data;

namespace WebApplication2
{
	public partial class Login : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack) 
			{
				if (Request.Cookies["UserID"] != null)
				{
					UserModel us = new UserModel();
					DataTable dt = UserInfoBLL.selectUser(Request.Cookies["UserID"].Value.ToString(), Request.Cookies["UserPwd"].Value.ToString());
					if (dt.Rows.Count > 0) 
					{
						us.UserID = dt.Rows[0]["UserID"].ToString();
						us.UserImage = dt.Rows[0]["UserImage"].ToString();
						us.UserName = dt.Rows[0]["UserName"].ToString();
						us.UserPwd = dt.Rows[0]["UserPwd"].ToString();
						us.UserEmail = dt.Rows[0]["UserEmail"].ToString();
						Page.Session["User"] = us;

						var user = Session["User"] as UserModel;

						Response.Write("<script>location.href='Homepage.aspx';</script>");
					}
				}
			}
		}
	}
}